package com.hdd.biz.painting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdd.biz.painting.dto.FileInfoRequest;
import com.hdd.biz.painting.dto.FileListRequest;
import com.hdd.biz.painting.dto.FileRequest;
import com.hdd.biz.painting.entity.FileInfo;
import com.hdd.biz.painting.entity.MaterialKind;
import com.hdd.biz.painting.mapper.FileInfoMapper;
import com.hdd.biz.painting.service.FileInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdd.dto.SuperRequest;
import com.hdd.dto.SuperResponse;
import com.hdd.utils.IdUtils;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 文件表 服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-03-10
 */
@Service
public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> implements FileInfoService {

    @Override
    public SuperResponse getMateriaSonList(FileListRequest request) {
        SuperResponse response = new SuperResponse();
        QueryWrapper<FileInfo> wrapper = new QueryWrapper();
        Page<FileInfo> pages = new Page<>(request.getPageNo(),request.getPageSize());
        wrapper.eq("material_kind_id",request.getPid());
        wrapper.eq("del_flag",0);
        wrapper.orderByDesc("sort");
        IPage<FileInfo> mapIPage = baseMapper.selectPage(pages, wrapper);
        List<FileInfo> agents = mapIPage.getRecords();
        response.setItems(agents);
        response.setTotals(pages.getTotal());
        return response;
    }


    @Override
    public SuperResponse materiaSonAdd(FileInfoRequest request) {
        SuperResponse response = new SuperResponse();
        FileInfo fileInfo = new FileInfo();
        fileInfo.setId(IdUtils.getUUID());
        fileInfo.setFileName(request.getFileName());
        fileInfo.setColorValue(request.getColorValue());
        fileInfo.setSize(request.getSize());
        fileInfo.setPath(request.getPath());
        fileInfo.setUrl(request.getUrl());
        fileInfo.setContentType(request.getContentType());
        fileInfo.setFramedShow(request.getFramedShow());
        fileInfo.setWidth(request.getWidth());
        fileInfo.setDelFlag(0);
        fileInfo.setType(request.getType());
        fileInfo.setSort(request.getSort());
        fileInfo.setMaterialKindId(request.getMaterialKindId());
        fileInfo.setMaterialType(request.getMaterialType());
        fileInfo.setUpSideUrl(request.getUpSideUrl());
        fileInfo.setUnderSideUrl(request.getUnderSideUrl());
        fileInfo.setRightSideUrl(request.getRightSideUrl());
        fileInfo.setLeftSideUrl(request.getLeftSideUrl());
        fileInfo.setUpperLeftUrl(request.getUpperLeftUrl());
        fileInfo.setUpperRightUrl(request.getUpperRightUrl());
        fileInfo.setUnderLeftUrl(request.getUnderLeftUrl());
        fileInfo.setUnderRightUrl(request.getUnderRightUrl());
        baseMapper.insert(fileInfo);
        return response;
    }


    @Override
    public SuperResponse materiaSonUpdate(FileInfoRequest request) {
        SuperResponse response = new SuperResponse();
        FileInfo fileInfo = new FileInfo();
        fileInfo.setId(request.getId());
        fileInfo.setFileName(request.getFileName());
        fileInfo.setColorValue(request.getColorValue());
        fileInfo.setSize(request.getSize());
        fileInfo.setPath(request.getPath());
        fileInfo.setUrl(request.getUrl());
        fileInfo.setContentType(request.getContentType());
        fileInfo.setFramedShow(request.getFramedShow());
        fileInfo.setWidth(request.getWidth());
        fileInfo.setDelFlag(0);
        fileInfo.setSort(request.getSort());
        fileInfo.setMaterialKindId(request.getMaterialKindId());
        fileInfo.setMaterialType(request.getMaterialType());
        fileInfo.setUpSideUrl(request.getUpSideUrl());
        fileInfo.setUnderSideUrl(request.getUnderSideUrl());
        fileInfo.setRightSideUrl(request.getRightSideUrl());
        fileInfo.setLeftSideUrl(request.getLeftSideUrl());
        fileInfo.setUpperLeftUrl(request.getUpperLeftUrl());
        fileInfo.setUpperRightUrl(request.getUpperRightUrl());
        fileInfo.setUnderLeftUrl(request.getUnderLeftUrl());
        fileInfo.setUnderRightUrl(request.getUnderRightUrl());
        baseMapper.updateById(fileInfo);
        return response;
    }


    @Override
    public SuperResponse materiaSonDel(FileRequest request) {
        SuperResponse response = new SuperResponse();
        FileInfo fileInfo = new FileInfo();
        fileInfo.setId(request.getId());
        fileInfo.setDelFlag(1);
        baseMapper.updateById(fileInfo);
        return response;
    }

}
